package cisdi.mes.sm.rm.web;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cisdi.mes.sm.rm.domain.SmRmMeasureDoc;
import cisdi.mes.sm.rm.service.MatReceiveMgr;

@Controller
public class MatReceiveCtl {

	@Autowired
	private MatReceiveMgr matReceiveMgr;
	
	public MatReceiveMgr getMatReceiveMgr() {
		return matReceiveMgr;
	}

	public void setMatReceiveMgr(MatReceiveMgr matReceiveMgr) {
		this.matReceiveMgr = matReceiveMgr;
	}

	@RequestMapping("/rm/MatReceiveCtl/matReceive")
	@ResponseBody
	public Map<String, Object> matReceive(HttpServletRequest request,@RequestParam("SmRmMeasureDoc") String measureDocString) {

		//定义输出
		Map<String, Object> serverInfo = new HashMap<String, Object>();

		try {
			// 数据转换
			ObjectMapper objectMapper = new ObjectMapper();
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			objectMapper.setDateFormat(dateFormat);
			SmRmMeasureDoc measureDoc = objectMapper.readValue(measureDocString,
					SmRmMeasureDoc.class);
			// 业务处理
			serverInfo = matReceiveMgr.matReceive(measureDoc,  request);
		} catch (Exception e) {
			e.printStackTrace();
			serverInfo.put("success", false);
			serverInfo.put("message", e.toString() + e.getMessage());
		}
		return serverInfo;
	}
	
	@RequestMapping("/rm/MatReceiveCtl/inputReceive")
	@ResponseBody
	public Map<String, Object> inputReceive(HttpServletRequest request,@RequestParam("SmRmMeasureDoc") String measureDocString) {

		// 定义输出
		Map<String, Object> serverInfo = new HashMap<String, Object>();

		try {
			// 数据转换
			ObjectMapper objectMapper = new ObjectMapper();
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			objectMapper.setDateFormat(dateFormat);
			SmRmMeasureDoc userDoc = objectMapper.readValue(measureDocString, SmRmMeasureDoc.class);

			// 业务处理
			serverInfo = matReceiveMgr.inputReceive(userDoc,  request);

		} catch (Exception e) {
			e.printStackTrace();
			serverInfo.put("success", false);
			serverInfo.put("message", e.getMessage());
		}
		return serverInfo;
	}
}
